package org.example.d3_collecion_list;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * list的循环方式：for循环，迭代器，foreach,Lambda(jdk1.8j开始之后的)
 */
public class ListTest {
    public static void main(String[] args) {
        List<String> list  = new ArrayList<>();
        list.add("蜘蛛精");
        list.add("至尊宝");
        list.add("至尊宝");
        list.add("牛夫人");

      //  for循环
        for (int i = 0; i < list.size(); i++) {
            String s = list.get(i);
            System.out.println(s);
        }
        //  迭代器，
        Iterator<String> it = list.iterator();
        while(it.hasNext()){
            System.out.println(it.next());
        }

        //  foreach,
        for (String s : list) {
            System.out.println(s);
        }
        //  Lambda(jdk1.8j开始之后的)
        list.forEach(s -> {
            System.out.println(s);
        });

    }
}
